package com.xc.freeapp.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xc.freeapp.entity.Scheduling;
import com.xc.freeapp.entity.Times;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.util.DateUtils;

/**
 * 
 * @author wukailuo 校验
 */
public class Verification {

	// 基本验证信息
	public static boolean verification(String businessId, String userId,
			String registrationId, String registerType) {
		boolean big = true;
		if (businessId == "" || businessId.length() > 11)
			big = false;
		if (userId == "" || userId.length() > 11)
			big = false;
		if (registrationId.length() < 0 || registrationId.length() > 15)
			big = false;
		if (registerType.length() < 0 || registerType.length() > 2)
			big = false;
		return big;
	}

	public static boolean qqemail(String updatetype, String updatevalue) {
		boolean log = true;

		int type = Integer.parseInt(updatetype);
		if (type < 0 || type > 3)
			log = false;
		if (type == 1 && updatevalue.length() > 32)
			log = false;
		if (type == 2 && Integer.parseInt(updatevalue) > 9999
				&& updatevalue.length() < 13)
			log = false;
		return log;
	}

	/**
	 * 根据日期计算所在周的周一和周日
	 * 
	 * @param
	 */
	public static Map<String, Object> convertWeekByDate() {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式

		int time = new Date().getHours();
		// 默认为1,这里与数据库相对应.1:早上2:中午3:晚上
		int status = 1;
		if (time < 12) {
			status = 0;
		}

		if (time>12&&time < 17) {
			status = 1;
		}

		if (time>17&&time < 22) {
			status =2;
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		// 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
		String imptimeBegin = sdf.format(cal.getTime());
		cal.add(Calendar.DATE, 6);
		String imptimeEnd = sdf.format(cal.getTime());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("imptimeBegin", imptimeBegin);
		map.put("imptimeEnd", imptimeEnd);
		map.put("status", status);
		return map;
	}

	public static List<Times> getsubscribe(List<Scheduling> bookingreg,
			Map<String, Object> map) throws BaseException, ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		Scheduling booking = new Scheduling();
		List<Times> timelist = new ArrayList<Times>();

		cal.setTime(DateUtils.getDate());
		Times time = new Times();
		for (int i = 0; i < 7; i++) {
			time = new Times();
			time.setNight(0);
			time.setNoon(0);
			time.setAfternoon(0);
			if (i == 0) {

				Date date = DateUtils.getDate();
				time.setWeek(DateUtils.getWeekDay(date));
				time.setTime(date);
			} else {
				cal.add(Calendar.DATE, 1);
				String dates = sdf.format(cal.getTime());

				Date date = DateUtils.stringToDate(dates, "yyyy-MM-dd");
				time.setWeek(DateUtils.getWeekDay(date));
				time.setTime(date);
			}
			for (int j = 0; j < bookingreg.size(); j++) {
				booking = bookingreg.get(j);
				String shijian = sdf.format(booking.getDatetime());
				String timesTime = sdf.format(time.getTime());
				if (timesTime.equals(shijian)) {
					if (booking.getWorks() == 1) {
						time.setNoon(1);
						time.setNoonid(bookingreg.get(j).getId());
					}

					if (booking.getWorks() == 2) {
						time.setAfternoon(1);
						time.setAfternoonid(bookingreg.get(j).getId());
					}

					if (booking.getWorks() == 3) {
						time.setNight(1);
						time.setNightid(bookingreg.get(j).getId());
					}

				}
			}
			timelist.add(time);
		}
		return timelist;
	}

	public static void main(String[] args) {
		Date date = new Date();
		Long time = date.getTime();
		System.out.println(time);

	}
}
